
includes("check_links.lua")
includes("check_ctypes.lua")
includes("check_cflags.lua")
includes("check_cfuncs.lua")

add_includedirs("include")
set_languages("c99")

set_configdir("$(buildir)/config")
add_configfiles("config.h.in")

configvar_check_links("HAS_POSIX_THREAD", {"pthread", "m", "dl"})
configvar_check_cfuncs("HAS_POSIX_MUTEX_API", 
{"pthread_mutex_init",
 "pthread_mutex_destroy", 
 "pthread_mutex_lock", 
 "pthread_mutex_unlock",
  "pthread_cond_init", 
  "pthread_cond_destroy", 
  "pthread_cond_signal",
  "pthread_cond_broadcast",
  "pthread_cond_wait",
  "pthread_cond_timedwait"
}, 
{includes = {"pthread.h"}})


configvar_check_cfuncs("HAS_POSIX_FILE_API", {"open", "close", "write", "read", "lseek", "fsync", "fstat"}, {includes = {"fcntl.h", "unistd.h", "sys/stat.h"}})
configvar_check_cfuncs("HAS_POSIX_DIR_API", {"opendir","closedir", "readdir", "rmdir", "mkdir", "access"}, {includes = {"dirent.h", "unistd.h", "sys/stat.h"}})
configvar_check_cfuncs("HAS_POSIX_DLL_API", {"dlopen", "dlclose", "dlsym", "dlerror"}, {includes = {"dlfcn.h"}})

configvar_check_cfuncs("HAS_STD_ATOMIC", 
{"atomic_fetch_add", "atomic_fetch_sub", "atomic_fetch_or", 
"atomic_fetch_and", "atomic_compare_exchange_strong"}, 
{includes = {"stdatomic.h"}})

add_includedirs("$(buildir)/config")

-- add rules: debug/release
add_rules("mode.debug", "mode.release")

add_subdirs("source" )


target("hello_world")
	set_kind("binary")
  add_deps("cbus")
	add_links("cbus")
	add_files("./test/hello_world/*.c")

		   
		   